// @Desc:
// @CreateTime: 2020/10/8
package main

import (
	"os"

	"gitee.com/xuesongtao/gotool/xlog"
	"github.com/gin-gonic/gin"
	"mycrm.com/config"
	"mycrm.com/corntask"
	"mycrm.com/module"
	"mycrm.com/router"
	"mycrm.com/utils"
)

// 项目初始化
func init() {
	projectDir, _ := os.Getwd()
	// 初始化配置信息
	config.InitConf(projectDir)

	// 初始化加解密
	utils.InitDecFn(projectDir)

	// 初始化数据库
	module.InitDb()

	// 初始化定时器
	corntask.InitCronTask()
}

func main() {
	routerObj := gin.Default()
	router.Routers(routerObj)
	isProduction := config.Configs.LogConf.IsProduction
	port := ":9999"
	if isProduction {
		port = ":8080"
	}
	if err := routerObj.Run(port); err != nil {
		xlog.Panic("server run is failed, err:", err)
	}
}
